﻿namespace AdminApp
{
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using AdminApp.Resources;
    using AdminApp.Web.Services;

    public partial class Home : Page
    {
        public Home()
        {
            InitializeComponent();

            this.Title = ApplicationStrings.HomePageTitle;
            this.Loaded += new System.Windows.RoutedEventHandler(Home_Loaded);

            App.Current.InstallStateChanged += (s, e) =>
            {
                CheckInstallButton();
            };

            CheckInstallButton();
        }

        private void CheckInstallButton()
        {
            if (!App.Current.IsRunningOutOfBrowser &&
                App.Current.InstallState != System.Windows.InstallState.Installed)
            {
                _installLocal.Visibility = System.Windows.Visibility.Collapsed;
            }
            else
            {
                _installLocal.Visibility = System.Windows.Visibility.Visible;
            }

        }

        void Home_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            DigitalSignageDomainContext context = new DigitalSignageDomainContext();
            var call = context.GetServerTime();
            call.Completed += (s, e1) =>
                {
                    _serverTime.Text = call.Value;
                };
        }

        /// <summary>
        ///     Executes when the user navigates to this page.
        /// </summary>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }
    }
}